import { defineStore } from "pinia";
import { UserState } from "@/stores/interface";
import piniaPersistConfig from "@/stores/helper/persist";

export const useUserStore = defineStore({
  id: "sw-user",
  state: (): UserState => ({
    token: "",
    userInfo: {
      userId: -1,
      userName: "",
      nickName: "",
      email: "",
      phonenumber: "",
      companyId: null,
      isCompanyAdmin: 0,
      roleIds: [],
      roleKeys: []
    }
  }),
  getters: {},
  actions: {
    // Set Token
    setToken(token: string) {
      this.token = token;
    },
    // Set setUserInfo
    setUserInfo(userInfo: UserState["userInfo"]) {
      this.userInfo = userInfo;
    },
    // ResetUserInfo
    resetUserInfo() {
      this.userInfo = {
        userId: -1,
        userName: "",
        nickName: "",
        email: "",
        phonenumber: "",
        companyId: null,
        isCompanyAdmin: 0,
        roleIds: [],
        roleKeys: []
      };
    }
  },
  persist: piniaPersistConfig("sw-user")
});
